/**
 * @Author: Nick Zhang <thesadboy@vip.qq.com>
 * @Description: 文档管理监听器，主要处理保存前逻辑
 * @Date: 2024-06-12 10:19:51
 * @LastEditors: Nick Zhang <thesadboy@vip.qq.com>
 * @LastEditTime: 2024-06-20 09:52:33
 */
package com.nickzhang.jetbrains.file_description_plugin.listeners

import com.intellij.openapi.editor.Document
import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.openapi.fileEditor.FileDocumentManagerListener
import com.nickzhang.jetbrains.file_description_plugin.configs.AppSettingState
import com.nickzhang.jetbrains.file_description_plugin.utils.CommentUtil

internal class AppFileDocumentManagerListener : FileDocumentManagerListener {
    override fun beforeDocumentSaving(document: Document) {
        val state: AppSettingState = AppSettingState.getInstance()
        if(!state.changeUpdate) return
        val file = FileDocumentManager.getInstance().getFile(document)
        file?.let { CommentUtil.updateCommentHeader(document, it) }
    }
}
